﻿using System;
using fastCSharp;

namespace diantou.web.ajax
{
    /// <summary>
    /// OJ测试操作
    /// </summary>
    [fastCSharp.code.cSharp.ajax(IsPool = true)]
    class judge : userHandle<judge>
    {
        /// <summary>
        /// 添加测试
        /// </summary>
        /// <param name="value"></param>
        /// <param name="isTimeError">是否频繁提交错误</param>
        /// <returns>测试提交标识,失败返回0</returns>
        public int Append(diantou.dataAccess.judge value, out bool isTimeError)
        {
            value.UserId = currentUser.Id;
            return diantou.dataAccess.tcpCall.judge.append(value, out isTimeError);
        }
        /// <summary>
        /// 添加基本测试
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn">回调函数</param>
        public void Run(diantou.dataAccess.judge value, Action<fastCSharp.net.returnValue<diantou.dataAccess.judgeClient.testJudge>> onReturn)
        {
            value.UserId = currentUser.Id;
            diantou.dataAccess.tcpCall.judge.run(value, onReturn);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="problemId">验证问题标识</param>
        /// <param name="language"></param>
        /// <returns>程序内容</returns>
        [fastCSharp.code.cSharp.ajax(IsOnlyPost = false)]
        public string Get(int id, int problemId, out diantou.dataModel.judgeState.languageType language)
        {
            return diantou.dataAccess.tcpCall.judge.getProgramContent(id, problemId, currentUser.Id, out language);
        }
        /// <summary>
        /// 获取程序草稿
        /// </summary>
        /// <param name="problemId"></param>
        /// <returns></returns>
        [fastCSharp.code.cSharp.ajax(IsOnlyPost = false)]
        public diantou.dataModel.programDraft GetDraft(int problemId)
        {
            return diantou.dataAccess.tcpCall.programDraft.get(currentUser.Id, problemId);
        }
        /// <summary>
        /// 保存程序草稿
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        public void SaveDraft(diantou.dataAccess.programDraft value, Action<fastCSharp.net.returnValue> onReturn)
        {
            value.UserId = currentUser.Id;
            diantou.dataAccess.tcpCall.programDraft.save(value, onReturn);
        }
        /// <summary>
        /// 分享代码
        /// </summary>
        /// <param name="id"></param>
        /// <param name="onReturn"></param>
        public void SetPublic(int id, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            diantou.dataAccess.tcpCall.judge.setPublic(id, currentUser.Id, onReturn);
        }
        /// <summary>
        /// 比赛基本测试
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn">回调函数</param>
        public void ContestRun(diantou.dataAccess.judge value, bool isJudge, Action<fastCSharp.net.returnValue<diantou.dataAccess.judgeClient.testJudge>> onReturn)
        {
            value.UserId = currentUser.Id;
            diantou.dataAccess.tcpCall.judge.contestRun(value, isJudge, onReturn);
        }
        /// <summary>
        /// 标程测试
        /// </summary>
        /// <param name="value"></param>
        /// <param name="timeUse"></param>
        /// <param name="isRun"></param>
        /// <param name="isProgram"></param>
        /// <param name="onReturn"></param>
        public void StandardProgram(diantou.dataAccess.judge value, int timeUse, bool isRun, bool isProgram, Action<fastCSharp.net.returnValue<diantou.dataAccess.judgeClient.testJudge>> onReturn)
        {
            value.UserId = currentUser.Id;
            diantou.dataAccess.tcpCall.judge.standardProgram(value, currentUser.Permission == dataModel.user.permission.Admin ? timeUse : 0, isRun, isProgram, onReturn);
        }
    }
}
